# Huawei Technologies Co.,Ltd.

if (PANDA_QEMU_BUILD)
    return()
endif()

set(JS_INFINITE_RECURSION_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/js_infinite_recursion.txt)
set(JS_INFINITE_RECURSION_BIN ${CMAKE_CURRENT_BINARY_DIR}/js_infinite_recursion.abc)
set(JS_INFINITE_RECURSION_PA ${CMAKE_CURRENT_BINARY_DIR}/js_infinite_recursion.pa)
set(JS_INFINITE_RECURSION_JS ${CMAKE_CURRENT_SOURCE_DIR}/js_infinite_recursion.js)
set(JS_INFINITE_RECURSION_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false --run-gc-in-place ${JS_INFINITE_RECURSION_BIN} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${JS_INFINITE_RECURSION_OUTPUT}
    COMMENT "running javascript newobjdynrange testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${JS_INFINITE_RECURSION_JS} --dump-assembly --output ${JS_INFINITE_RECURSION_BIN} > ${JS_INFINITE_RECURSION_PA}
    COMMAND rm -f ${JS_INFINITE_RECURSION_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} > ${JS_INFINITE_RECURSION_OUTPUT}
    COMMAND bash ${JS_INFINITE_RECURSION_VERIFY} ${JS_INFINITE_RECURSION_OUTPUT}
)
add_custom_target(js_infinite_recursion
    DEPENDS ${JS_INFINITE_RECURSION_OUTPUT} ${JS_INFINITE_RECURSION_VERIFY}
)
add_dependencies(js_infinite_recursion es2panda ark)
add_dependencies(ecmascript_common_tests js_infinite_recursion)
